package com.zuxia.action;



import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.zuxia.iservices.RecruitmentManagementServicesI;
import com.zuxia.po.Positioninfo;
import com.zuxia.po.Recruitinfo;
import com.zuxia.po.Recruitrecordinfo;
import com.zuxia.util.PageModel;
public class RecruitmentManagementAction extends BaseAction {
	public RecruitmentManagementServicesI recruitmentManagementServices;
	private Integer riid;
	private String rirequirement;
	private Integer riicount;
	private Date riibeginTime;
	private Date riiendTime;
	public int ptIid;
	//修改
	public String ptIname;
	public String riaddress;
	
	//分页
	public int limit;
	public int pageNumber;
	
	//排序
	public String order;
	
	//应聘记录表
	public Recruitrecordinfo recruitrecordinfo;
	
	//删除应聘记录
	public void deleteRecruitrecordinfo(){
		Boolean b= recruitmentManagementServices.deleteRecruitrecordinfo(recruitrecordinfo.getRriid());
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//分页查询应聘者
	public void showRecruitrecordinfo(){
		PageModel<Recruitrecordinfo> pagelist =recruitmentManagementServices.showRecruitrecordinfo(ptIid,pageNumber,limit,order);
	 	String json = JSONArray.toJSONString(pagelist,SerializerFeature.DisableCircularReferenceDetect);
	 	//返回给客户端
	 	try {
	 		getResponse().setCharacterEncoding("utf-8");
	 		getResponse().getWriter().print(json);
	 	} catch (Exception e) {
	 	// TODO Auto-generated catch block
	 		e.printStackTrace();
	 	}
	}
	
	
	//添加应聘前查询
	public void addShowRecruitrecordinfo(){
		Boolean b=recruitmentManagementServices.addShowRecruitrecordinfo(recruitrecordinfo,ptIid);
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//添加应聘记录
	public void addRecruitrecordinfo(){
		Boolean b=recruitmentManagementServices.addRecruitrecordinfo(recruitrecordinfo,ptIid);
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//查询所有
	public void selectRecruitinfo(){
		List<Recruitinfo> list =recruitmentManagementServices.showRecruitinfo();
	 	String json = JSONArray.toJSONString(list);
	 	//返回给客户端
	 	try {
	 		getResponse().setCharacterEncoding("utf-8");
	 		getResponse().getWriter().print(json);
	 	} catch (Exception e) {
	 	// TODO Auto-generated catch block
	 		e.printStackTrace();
	 	}
	}
	
	//修改需求
	public void updateRecruitinfo(){
		Boolean b=recruitmentManagementServices.updateRecruitinfo(riid,riaddress,riicount,riiendTime,rirequirement);
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//查询一个Recruitinfo对象
	public void riidShowRecruitinfo(){
		Recruitinfo r=recruitmentManagementServices.riidShowRecruitinfo(riid);
		String json = JSONArray.toJSONString(r);
		//返回给客户端
		try {
			getResponse().getWriter().print(json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("查询到的需求职位json字符串如下！"+json);
	}
	
	//删除指定需求
	public void deleteRecruitinfo(){
		Boolean b= recruitmentManagementServices.deleteRecruitinfo(riid);
		//返回给客户端
		try {
			System.out.println(riid);
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//分页查询
	public void showRecruitinfo(){
	 	PageModel<Recruitinfo> pagelist =recruitmentManagementServices.showRecruitinfo(ptIname,pageNumber,limit);
	 	String json = JSONArray.toJSONString(pagelist);
	 	//返回给客户端
	 	try {
	 		getResponse().setCharacterEncoding("utf-8");
	 		getResponse().getWriter().print(json);
	 	} catch (Exception e) {
	 	// TODO Auto-generated catch block
	 		e.printStackTrace();
	 		}
	 	}
	
	public void ptIidShowRecruitinfo(){
		//查询该需求职位是否存在
		Boolean b= recruitmentManagementServices.ptIidShowRecruitinfo(ptIid);
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void positioninfoShowAll(){
		List<Positioninfo> list =recruitmentManagementServices.showPositioninfo();
		System.out.println(list.size());
		String json = JSONArray.toJSONString(list);
		//返回给客户端
		try {
			getResponse().setCharacterEncoding("utf-8");
			getResponse().getWriter().print(json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void positioninfoShowId(){
		Positioninfo p =recruitmentManagementServices.idshow(ptIid);
		String json = JSONArray.toJSONString(p);
		//返回给客户端
		try {
			getResponse().getWriter().print(json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("查询到的职位json字符串如下！"+json);
	}
	
	public void addrecruitinfo(){
		System.out.println("进入");
		Positioninfo p=recruitmentManagementServices.positioninfoFindById(ptIid);
		//处理关系
		Recruitinfo recruitinfo=new Recruitinfo(null,p,rirequirement,riaddress,0,riicount, riibeginTime, riiendTime);
		Boolean b =recruitmentManagementServices.addrecruitinfo(recruitinfo,p);
		//返回给客户端
		try {
			getResponse().getWriter().print(b);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	public RecruitmentManagementServicesI getRecruitmentManagementServices() {
		return recruitmentManagementServices;
	}


	public void setRecruitmentManagementServices(
			RecruitmentManagementServicesI recruitmentManagementServices) {
		this.recruitmentManagementServices = recruitmentManagementServices;
	}


	public int getPtIid() {
		return ptIid;
	}


	public void setPtIid(int ptIid) {
		this.ptIid = ptIid;
	}


	public Integer getRiid() {
		return riid;
	}


	public void setRiid(Integer riid) {
		this.riid = riid;
	}


	public String getRirequirement() {
		return rirequirement;
	}


	public void setRirequirement(String rirequirement) {
		this.rirequirement = rirequirement;
	}


	public Integer getRiicount() {
		return riicount;
	}


	public void setRiicount(Integer riicount) {
		this.riicount = riicount;
	}


	public Date getRiibeginTime() {
		return riibeginTime;
	}


	public void setRiibeginTime(Date riibeginTime) {
		this.riibeginTime = riibeginTime;
	}


	public Date getRiiendTime() {
		return riiendTime;
	}


	public void setRiiendTime(Date riiendTime) {
		this.riiendTime = riiendTime;
	}

	public String getPtIname() {
		return ptIname;
	}

	public void setPtIname(String ptIname) {
		this.ptIname = ptIname;
	}

	public String getRiaddress() {
		return riaddress;
	}

	public void setRiaddress(String riaddress) {
		this.riaddress = riaddress;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public Recruitrecordinfo getRecruitrecordinfo() {
		return recruitrecordinfo;
	}

	public void setRecruitrecordinfo(Recruitrecordinfo recruitrecordinfo) {
		this.recruitrecordinfo = recruitrecordinfo;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}
	
	
}
	
